<template>
	<view>
		<view class="steps">
			<uni-steps :options="list1" active-color="#007AFF"  :active="active" />
			<view>
				<view>
					<form @submit="formSubmit" @reset="formReset">
						<view class="uni-form-item uni-column">
							<view class="title">紧急联系人</view>
							<view>
								<input class="uni-input" name="concatRelation" placeholder="请输入紧急联系人"/>
							</view>
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">联系人关系</view>
							<view>
								<input class="uni-input" name="concatName" placeholder="请输入联系人关系" />
							</view>
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">联系人手机号</view>
							<view>
								<input class="uni-input" name="concatPhone" placeholder="请输入联系人手机号" />
							</view>
						</view>
						<input name="birthday" type="hidden" disabled="true" />
						<view class="uni-btn-v">
							<button form-type="submit" class="button-green" @click="change()">确认注册</button>
						</view>
					</form>
				</view>
			</view>
		</view>
	</view>
	</view>
</template>
<script>
	import {parseTime} from"../../../api/ruoyi.js"
	import {stuRegister} from"../../../api/student.js"
	export default {
		data() {
			return {
				date:"",
				preStudent:{},
				/* student:{
					studentId:0,
					studentNumber:"",
					studentName:"",
					studentSex:"",
					studentBirthday:"",
					studentPhone:"",
					studentIdNumber:"",
					studentAddress:"",
					note:"",
					concatRelation:"",
					concatName:"",
					concatPhone:""
				}, */
				student2:{
					studentNumber:"",
					studentName:"",
					studentSex:"",
					studentBirthday:"",
					studentPhone:"",
					studentIdNumber:"",
					studentAddress:"",
					note:"",
					concatRelation:"",
					concatName:"",
					concatPhone:""
				},
				active: 1,
				list1: [{
						title: '学员信息'
					},
					{
						title: '补充信息'
					},
					{
						title: '报名/试听'
					},
				]
			}
		},
		onLoad(option) {
			/* this.getStudentNumberByDate() */
			this.student=JSON.parse(decodeURIComponent(option.obj));//1 加载页面时 接收前置对象
		},
		methods: {
			change() { //改变步骤条
				if (this.active < this.list1.length - 1) {
					this.active += 1
					if (this.active = 3) {
						uni.navigateTo({
							url: "./registered3?obj="+encodeURIComponent(JSON.stringify(this.student))
						})
					}
				}
			},
			formSubmit: function(e) {
				var formdata = e.detail.value//表单对象
				this.student.concatRelation = formdata.concatRelation
				this.student.concatName = formdata.concatName
				this.student.concatPhone = formdata.concatPhone
				const aftStudent = this.student;
				console.log(aftStudent,'表单提交之前')
				const data = {
					studentNumber:aftStudent.studentNumber,
					studentName:aftStudent.studentName,
					studentSex:aftStudent.studentSex,
					studentBirthday:aftStudent.studentBirthday,
					studentPhone:aftStudent.studentPhone,
					studentIdNumber:aftStudent.studentIdNumber,
					studentAddress:aftStudent.studentAddress,
					note:aftStudent.note,
					concatRelation:aftStudent.concatRelation,
					concatName:aftStudent.concatName,
					concatPhone:aftStudent.concatPhone
				}
				//请求添加学生接口
				stuRegister(data).then(res=>{
					console.log(res.data.studentId,'学生id')
					this.student.studentId = res.data.studentId
					console.log(this.student,'--------------------------------')
					uni.setStorage({
						key:'studentId',
						data:this.student.studentId
					})
					uni.showToast({
						title:"注册成功"
					})
				})
			},
			formReset: function(e) {
				console.log('清空数据')
			}
		}
	}
</script>
<style scoped>
	.steps {
		margin-top: 18px;

	}
	.uni-form-item .title {
		padding: 20rpx 0;
		margin-left: 40px;
	}

	.uni-column {
		display: flex;
		margin-top: 15px;
	}
	input{
		margin:10px 10px
	}

</style>
